<template>
  <div class="">
    <el-dialog title="编辑用户" :visible="showDialog" @close="btnCancel">
      <el-form
        label-width="140px"
        :model="addForm"
        style="padding-right:180px"
        :rules="rules"
        ref="addForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="addForm.username" />
        </el-form-item>

        <el-form-item label="邮箱" prop="email">
          <el-input v-model="addForm.email" />
        </el-form-item>

        <el-form-item label="角色">
          <el-input v-model="addForm.role" />
        </el-form-item>

        <el-form-item label="权限组名称">
          <!-- <el-input v-model="addForm.permission_group_title" /> -->
          <el-select
            v-model="addForm.permission_group_title"
            placeholder="请选择"
            style="width:49%;margin-right:2%"
          >
            <el-option value="123"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="联系电话">
          <el-input v-model="addForm.phone" />
        </el-form-item>

        <el-form-item label="介绍">
          <el-input v-model="addForm.introduction" type="textarea" />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-row type="flex" justify="center">
          <el-button @click="btnCancel">取 消</el-button>
          <el-button type="primary" @click="btnOK">确 定</el-button>
        </el-row>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { editManagementList } from '@/api/management'
export default {
  name: '',
  components: {},
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    addForm: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }]
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    btnOK() {
      // try {
      //   await this.$refs.addForm.validate()
      //   await editManagementList(this.addForm)
      //   this.$emit('btnOK')
      //   this.$emit('update:showDialog', false)
      //   this.$message.success('修改成功')
      // } catch (error) {
      //   this.$message.error('操作失败')
      // }
      this.$refs.addForm.validate(async isOk => {
        if (isOk) {
          const res = await editManagementList(this.addForm)
          // this.$emit('btnOK') // 告诉父组件 从新拉取数据
          // this.$emit('update:showDialog', false)
          console.log(res)
          // console.log(
          //   await editManagementList({ ...this.addForm, id: this.addForm.id })
          // )
        }
      })
    },
    btnCancel() {
      this.$emit('btnCancel')
      this.$emit('update:showDialog', false)
      this.$refs.addForm.resetFields()
    }
  }
}
</script>
<style lang="less" scoped></style>
